package edu.caece.langprocessor.syntax.parse;

import java.util.ArrayList;
import java.util.Map;
import java.util.Stack;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import edu.caece.langprocessor.lexical.LexicalProcessor;
import edu.caece.langprocessor.lexical.tokens.LexicalToken;
import edu.caece.langprocessor.syntax.ProductionFactory;
import edu.caece.langprocessor.syntax.Terminal;
import edu.caece.langprocessor.syntax.tree.Tree;

public class ShiftAction extends Action {

	private static final Log LOGGER = LogFactory.getLog(ShiftAction.class);

	public ShiftAction(Integer value) {
		this.type = ActionType.shift;
		this.value = value;
	}

	@Override
	public ActionResult run(LexicalProcessor lexicalProcessor,
			Map<Integer, ProductionFactory> productions, 
			GotoActionsTable gotoActionsTable,
			Stack<ParseStackItem> parseStack, Terminal terminalItem, 
			Tree parseTree) {

		ParseStackItem p = new ParseStackItem(terminalItem, value);
		parseStack.push(p);
		LexicalToken t = lexicalProcessor.getNextLexicalToken();

		if (LOGGER.isDebugEnabled())
			LOGGER.debug("Shift applied. Terminal " + terminalItem + " pushed. New state: " + this.value);
		
		return new ActionResult(new Terminal(t), null,0,new ArrayList<Terminal>());
	}

}
